package com.yuwei.property.adapter

import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.http.entity.PropertyEntity
import com.yuwei.http.entity.PropertyEntityItem
import com.yuwei.property.R

class AreaAdapter: BaseQuickAdapter<String, BaseViewHolder>(R.layout.area_item) {
    private var position : Int = -1
    var regionList = mutableListOf<PropertyEntityItem>()
    private val regionAdapter = RegionAdapter()
    fun setPosition(position: Int) {
        this.position = position
    }
    fun getPosition(): Int {
        return position
    }
    fun setRegionList(regionList: PropertyEntity) {
        this.regionList = regionList
    }

    override fun convert(holder: BaseViewHolder, item: String) {
        regionAdapter.data.clear()
        regionAdapter.data.addAll(regionList)
        regionAdapter.notifyDataSetChanged()
        val tv = holder.getView<TextView>(R.id.tv_area_name)
        tv.text = item
        val rv = holder.getView<RecyclerView>(R.id.area_item_region_rv)
        if (position == holder.adapterPosition){
            rv.visibility = View.VISIBLE

        }else{
            rv.visibility = View.GONE
        }
        rv.adapter = regionAdapter
        rv.layoutManager = LinearLayoutManager(rv.context,LinearLayoutManager.HORIZONTAL,false)
    }
}